home *** CD-ROM | disk | FTP | other *** search
/ Enter 2005 October / enter-2005-10.iso / files / jedit42install.exe / {app} / jedit.jar / bsh / commands / thinBorder.bsh < prev    next >
Encoding:
Text File  |  2003-12-27  |  1.8 KB  |  71 lines

  1. /** 
  2.  * A one pixel wide bevel border.  This border works for buttons (with optional
  3.  * rollover) and other components
  4.  *
  5.  * @author Daniel Leuck
  6.  */
  7. import javax.swing.border.*;
  8.  
  9. Insets INSETS = new Insets(1,1,1,1);
  10.  
  11. public thinBorder() { return thinBorder(null, null, false); }
  12.  
  13. public thinBorder(Color lightColor, Color darkColor) {
  14.     return thinBorder(lightColor, darkColor, false);    
  15. }
  16.  
  17. public thinBorder(Color lightColor, Color darkColor, boolean rollOver) {            
  18.             
  19.     /**
  20.      * Draw a 1 pixel border given a color for topLeft and bottomRight.    
  21.      */
  22.     drawBorder(g, x, y, width, height, topLeft, bottomRight) {
  23.         Color oldColor = g.color;
  24.         
  25.         g.color=topLeft;
  26.         g.drawLine(x, y, x+width-1, y);
  27.         g.drawLine(x, y, x, y+height-1);
  28.         
  29.         g.color=bottomRight;
  30.         g.drawLine(x+width-1, y, x+width-1, y+height-1);
  31.         g.drawLine(x, y+height-1, x+width-1, y+height-1);        
  32.         
  33.         g.color=oldColor;
  34.     }
  35.         
  36.     public void paintBorder(c, g, x, y, width, height) {    
  37.         Color bgColor = c.background;    
  38.         Color dark = (darkColor==null) ? bgColor.darker().darker() :
  39.                 darkColor;
  40.         Color light = (lightColor==null) ? bgColor.brighter() :
  41.                 lightColor;            
  42.         
  43.         if(c instanceof AbstractButton) {
  44.             if(c.rolloverEnabled && !c.model.rollover && c.opaque)    {
  45.                 drawBorder(g, x, y, width, height, bgColor, bgColor);                    
  46.             } else {
  47.                 if(c.model.pressed)
  48.                     drawBorder(g, x, y, width, height, dark, light);
  49.                 else
  50.                     drawBorder(g, x, y, width, height, light, dark);
  51.             }
  52.         } else {
  53.             drawBorder(g, x, y, width, height, light, dark);        
  54.         }
  55.     }
  56.  
  57.     /**
  58.      * Returns the insets of the border.
  59.      *
  60.      * @param c the component for which this border insets value applies
  61.      */
  62.     public Insets getBorderInsets(Component c) { return INSETS; } 
  63.     
  64.     /**
  65.      * Always returns false
  66.      */
  67.     public boolean isBorderOpaque() { return false; }
  68.     
  69.     return this;
  70. }
  71.